package cst.a806yf.zyfypt_806yf.Fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cst.a806yf.zyfypt_806yf.Adapter.ArticleAdapter;
import cst.a806yf.zyfypt_806yf.Bean.ArticleBean;

import cst.a806yf.zyfypt_806yf.R;
import cst.a806yf.zyfypt_806yf.Model.ResModel;
import cst.a806yf.zyfypt_806yf.Linstener.AmicoolListener;

/**
 * Created by Neusoft on 2017/4/9.
 */



public class Fragment1 extends android.support.v4.app.Fragment {
    private RecyclerView recyclerView;
    private ArticleAdapter adapter;
    private List<ArticleBean>  list;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<ArticleBean>> listener;
    private ResModel model;
    private SharedPreferences sp;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_fragment_1,container,false);
        recyclerView = (RecyclerView)view.findViewById(R.id.rec_artcle);
        adapter = new ArticleAdapter(getActivity());
        list = new ArrayList<ArticleBean>();
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
   listener = new AmicoolListener<List<ArticleBean>>() {
       @Override
       public void onResponse(List<ArticleBean> l) {
           adapter.setList(l);
       }

       @Override
       public void onFail(String msg) {

       }
   };
   sp = getActivity().getSharedPreferences("ME", Context.MODE_APPEND);
   model = new ResModel("gson",sp.getString("session_id",""));
   model.getList("article",1,listener);
        return view;
    }
}